package com.bangcommunity.bbframe.common.exception;

import java.io.Serializable;

/**
 * @author tanghc
 */
public class BaseException extends Exception implements Serializable {

    private static final long serialVersionUID = 1L;
    private String errorCode;
    private String messageForClient;

    public BaseException(String errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
    }

    public BaseException(String errorCode, String message, String messageForClient) {
        super(message);
        this.errorCode = errorCode;
        this.messageForClient = messageForClient;
    }

    public BaseException(String errorCode, String message, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
    }

    public BaseException(String errorCode, String message, String messageForClient, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
        this.messageForClient = messageForClient;
    }

    public BaseException(Exception e) {
        super(e);
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(String message, Throwable cause) {
        super(message, cause);
    }

    @Override
    public String getMessage() {
        return super.getMessage();
    }

    public String getMessageForClient() {
        return messageForClient;
    }

    public String getErrorMessage() {
        String msg = getMessageForClient();
        if (null == msg || msg.trim().length() == 0) {
            msg = getMessage();
        }
        return msg;
    }

    public void setMessageForClient(String messageForClient) {
        this.messageForClient = messageForClient;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    @Override
    public String toString() {
        return "BaseException{" + "errorCode='" + errorCode + '\'' + "errorMessage='" + getErrorMessage() + '\''
                + ", messageForClient='" + messageForClient + '\'' + '}';
    }
}